﻿namespace Tool.Utils
{
    public static class FormHelper
    {
        public static FormUrlEncodedContent GetUserFormData(string sqlContent, string clientName, string groupName)
        {
            var collection = new List<KeyValuePair<string, string>>();
            collection.Add(new("instance_name", GetUserInstanceName(clientName, groupName)));
            collection.Add(new("db_name", GetUserDbName(clientName, groupName)));
            collection.Add(new("schema_name", ""));
            collection.Add(new("tb_name", ""));
            collection.Add(new("sql_content", sqlContent));
            collection.Add(new("limit_num", "10"));
            var content = new FormUrlEncodedContent(collection);
            return content;
        }

        public static FormUrlEncodedContent GetReimFormData(string sqlContent, string clientName, string groupName, string evdType = "BX")
        {
            var collection = new List<KeyValuePair<string, string>>();
            collection.Add(new("instance_name", GetReimInstanceName(clientName, groupName, evdType)));
            collection.Add(new("db_name", GetReimDbName(clientName, groupName, evdType)));
            collection.Add(new("schema_name", ""));
            collection.Add(new("tb_name", ""));
            collection.Add(new("sql_content", sqlContent));
            collection.Add(new("limit_num", "100"));
            var content = new FormUrlEncodedContent(collection);
            return content;
        }

        public static FormUrlEncodedContent GetSyncReimFormData(string sqlContent, string clientName, string groupName)
        {
            var collection = new List<KeyValuePair<string, string>>();
            collection.Add(new("instance_name", GetSyncReimInstanceName(clientName, groupName)));
            collection.Add(new("db_name", GetSyncReimDbName(clientName, groupName)));
            collection.Add(new("schema_name", ""));
            collection.Add(new("tb_name", ""));
            collection.Add(new("sql_content", sqlContent));
            collection.Add(new("limit_num", "100"));
            var content = new FormUrlEncodedContent(collection);
            return content;
        }

        public static FormUrlEncodedContent GetPushLogFormData(string sqlContent, string clientName, string groupName)
        {
            var collection = new List<KeyValuePair<string, string>>();
            collection.Add(new("instance_name", GetSyncReimInstanceName(clientName, groupName)));
            collection.Add(new("db_name", GetPushLogDbName(clientName, groupName)));
            collection.Add(new("schema_name", ""));
            collection.Add(new("tb_name", ""));
            collection.Add(new("sql_content", sqlContent));
            collection.Add(new("limit_num", "100"));
            var content = new FormUrlEncodedContent(collection);
            return content;
        }

        public static FormUrlEncodedContent GetTableStructFormData(string instanceName, string dbName, string tableName)
        {
            var collection = new List<KeyValuePair<string, string>>();
            collection.Add(new("instance_name", instanceName));
            collection.Add(new("db_name", dbName));
            collection.Add(new("schema_name", ""));
            collection.Add(new("tb_name", tableName));
            var content = new FormUrlEncodedContent(collection);
            return content;
        }

        public static string GetUserInstanceName(string clientName, string groupName)
        {
            switch (clientName)
            {
                case "zwy":
                    if (groupName == "托管")
                        return "托管从库172";
                    else if (groupName == "云南" || groupName == "企业")
                        return "yunnan_mysql_195从库";
                    return "托管从库172";
                case "sh":
                    return "上海达梦";
                case "yn":
                    return "云南达梦81";
                case "sx":
                    return "托管从库114.8";
                default:
                    return "订单-167";
            }
        }

        public static string GetReimInstanceName(string clientName, string groupName, string evdType = "BX")
        {
            switch (clientName)
            {
                case "zwy":
                    if (groupName == "托管")
                        if (evdType == "FB")
                        {
                            return "劳务_251";
                        }
                        else
                        {
                            return "托管从库172";
                        }

                    else if (groupName == "云南" || groupName == "企业")
                        return "yunnan_mysql_195从库";
                    else
                    {
                        if (evdType == "FB")
                        {
                            return "劳务_251";
                        }
                        else
                        {
                            return "托管从库172";
                        }
                    }
                case "sh":
                    return "上海达梦";
                case "yn":
                    return "云南达梦78";
                case "sx":
                    return "托管从库114.8";
                default:
                    return "";
            }
        }

        public static string GetSyncReimInstanceName(string clientName, string groupName)
        {
            switch (clientName)
            {
                case "zwy":
                    return "托管中心从库48";
                case "sh":
                    return "上海达梦";
                case "yn":
                    return "云南达梦78";
                case "sx":
                    return "托管从库114.8";
                default:
                    return "";
            }
        }

        public static string GetUserDbName(string clientName, string groupName)
        {
            switch (clientName)
            {
                case "zwy":
                    if (groupName == "托管")
                        return "gwhome_user_saas";
                    else if (groupName == "云南")
                        return "gwhome_user_yunnan";
                    else if (groupName == "企业")
                        return "gwhome_user_ent";
                    return "gwhome_user_saas";
                case "sh":
                    return "gwhome_user_sh";
                case "yn":
                    return "gwhome_user_yn";
                case "sx":
                    return "gwhome_user_bj";
                default:
                    return "gwhome_center_user";
            }
        }

        public static string GetReimDbName(string clientName, string groupName, string evdType = "BX")
        {
            switch (clientName)
            {
                case "zwy":
                    if (groupName == "托管")
                        switch (evdType)
                        {
                            case "FB":
                                return "office_supplies";
                            default:
                                return "gwhome_reim_saas";
                        }

                    else if (groupName == "云南")
                        switch (evdType)
                        {
                            case "FB":
                                return "office_supplies_yunnan";
                            default:
                                return "gwhome_reim_yunnan";
                        }

                    else if (groupName == "企业")
                        switch (evdType)
                        {
                            case "FB":
                                return "office_supplies_ent";
                            default:
                                return "gwhome_reim_ent";
                        }
                    else
                    {
                        switch (evdType)
                        {
                            case "FB":
                                return "office_supplies";
                            default:
                                return "gwhome_reim_saas";
                        }
                    }
                case "sh":

                    return "gwhome_reim_sh";
                case "yn":
                    return "gwhome_reim_yn";
                case "sx":
                    return "gwhome_reim_bj";
                default:
                    return "";
            }
        }

        public static string GetSyncReimDbName(string clientName, string groupName)
        {
            switch (clientName)
            {
                case "zwy":
                    return "gwhome_evc";
                case "sh":
                    return "gwhome_evc_sh";
                case "yn":
                    return "gwhome_evc_yn";
                case "sx":
                    return "gwhome_evc_bj";
                default:
                    return "";
            }
        }

        public static string GetPushLogDbName(string clientName, string groupName)
        {
            switch (clientName)
            {
                case "zwy":
                    return "gatekeeper";
                case "sh":
                    return "gatekeeper_sh";
                case "yn":
                    return "gwhome_evc_yn";
                case "sx":
                    return "gwhome_evc_bj";
                default:
                    return "";
            }
        }

        public static string GetGroupName(int groupId)
        {
            switch (groupId)
            {
                case 1:
                    return "托管";
                case 2:
                    return "云南";
                case 3:
                    return "企业";
                case 8:
                    return "上海";
                case 9:
                    return "新云南";
                case 11:
                    return "北京";
                default:
                    return "未知";
            }
        }
    }
}
